# -*- encoding:utf-8 -*-
# __author__ = 'chenyongbing'
# __poject__ = 'ops_platform'
# __datetime__ = '2022/8/4'
# __name__ = 'regrade.py'

from .mixin import FlowMixin
from apps.cicd.handles.base import workorder_update_deployment_resources, workorder_pod_status

# Create your code here.

class RegradeFlow(FlowMixin):
    '''
    升级配置 cpu、memory and  env java_opts
    '''
    def exec__regrade(self, action='yes'):
        if action == 'no':
            return 'finish', 'error'
        if self.workorder.nodeploy == 1:
            self._logging_warn('在环境 {} 拒绝部署'.format(self.workorder.env.name))
            return 'finish', 'success'
        ret = workorder_update_deployment_resources(self.workorder)
        if not ret:
            return 'fail', 'fail'
        return 'finish', 'success'


    def exec__regrade_auto(self, action='yes'):
        '''
        自动执行
        :param action:
        :return:
        '''
        if self.workorder.nodeploy == 1:
            self._logging_warn('在环境 {} 拒绝部署'.format(self.workorder.env.name))
            return 'finish', 'success'
        ret = workorder_pod_status(self.workorder)
        if ret:
            return 'finish', 'success'
        else:
            return 'fail', 'fail'
